package com.campus.campusdelivery.entity;

import com.campus.campusdelivery.constant.DeliveryStatus;
import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

@Entity
@Table(name = "delivery_persons")
@Data
@NoArgsConstructor
@AllArgsConstructor
@EntityListeners(AuditingEntityListener.class)
public class DeliveryPerson {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    private User user;
    
    @Column(length = 20)
    private String idCard;
    
    @Column(length = 200)
    private String address;
    
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private DeliveryStatus status = DeliveryStatus.OFFLINE;
    
    @Column
    private Double currentLatitude;
    
    @Column
    private Double currentLongitude;
    
    @Column
    private LocalDateTime lastLocationUpdate;
    
    @Column(nullable = false)
    private Integer totalDeliveries = 0;
    
    @Column(nullable = false)
    private Double rating = 5.0;
    
    @Column(nullable = false)
    private Integer ratingCount = 0;
    
    @CreatedDate
    @Column(nullable = false, updatable = false)
    private LocalDateTime createTime;
    
    @LastModifiedDate
    @Column(nullable = false)
    private LocalDateTime updateTime;
}
